package com.qf.lanzhou.shop.api.controller;


import com.qf.lanzhou.shop.api.service.RegisterService;
import com.qf.lanzhou.shop.pojo.entity.User;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * @Author jian
 * @Date 2021/1/8 11:28
 * @JDK 1.8
 * @Version 1.0
 */
@Controller
@Api("注册")
//@RequestMapping("/register.do")
public class RegisterController extends BaseController {

    @Autowired
    private RegisterService registerService;


    @RequestMapping(value = "/register.do", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("注册功能")
    public BaseRespVO register(String userName, String password, String phone, String email, String sex, int age) {


        User user = registerService.checkusername(userName);
        if (user != null) {
            //用户名已存在
            System.out.println("用户名已存在");
            return convertErrorResult("用户名已存在");
        }


        int i = registerService.insert(userName, password, phone, email, sex, age);
        if (i == 1) {
            return convertSuccessResult("注册成功");

        }
        return convertErrorResult("服务器繁忙");
    }

}
